package com.adjy.pathbuilders.objects.button.listeners;

import com.adjy.pathbuilders.objects.button.ImageButton;
import com.adjy.pathbuilders.rendering.loading.WeakReferenceBitmap;

public abstract class MutableButtonListener implements ButtonListener {

	private ImageButton button;
	private WeakReferenceBitmap selectedImage1;
	private WeakReferenceBitmap unselectedImage1;
	private WeakReferenceBitmap selectedImage2;
	private WeakReferenceBitmap unselectedImage2;
	private int state;

	public MutableButtonListener(WeakReferenceBitmap selectedImage1, WeakReferenceBitmap unselectedImage1, WeakReferenceBitmap selectedImage2, WeakReferenceBitmap unselectedImage2) {
		this.state = 1;
		this.selectedImage1   =   selectedImage1;
		this.unselectedImage1 = unselectedImage1;
		this.selectedImage2   =   selectedImage2;
		this.unselectedImage2 = unselectedImage2;
	}
	
	public void setButton(ImageButton button) {
		this.button = button;
	}
	
	@Override
	public void onButtonPressed() {
		if(state == 1){
			this.onButtonPressed1();
		} else {
			this.onButtonPressed2();
		}
	}
	
	public abstract void onButtonPressed1();
	public abstract void onButtonPressed2();
	
	public void setState(int i){
		if(i==1){
			this.state = 1;
			this.button.setSelectedImage(selectedImage1);
			this.button.setUnselectedImage(unselectedImage1);
		} else {
			this.state = 2;
			this.button.setSelectedImage(selectedImage2);
			this.button.setUnselectedImage(unselectedImage2);
		}
	}

}
